class Vote
  include Mongoid::Document
  belongs_to :question_version

  field :plus, type: Array, default: []
  field :minus, type: Array, default: []
  field :zero, type: Array, default: []

  def vote(user, value)
    return unless [1, 0, -1].include? value
    plus.delete(user.id)
    minus.delete(user.id)
    zero.delete(user.id)
    self.send([:minus, :zero, :plus][value + 1]) << user.id
    self.save
  end

  after_create do |doc|
    User.each { |u|
      #send notification to u
    }
  end

  def plus_count
    self.plus.count
  end
  def zero_count
    self.zero.count
  end
  def minus_count
    self.minus.count
  end
end
